Add ability to load development-only environment variables#22
Merged
Add ability to load development-only environment variables#22
Conversation
- Added `addDevEnvVariables` util function to allow the extension to load the local `.env` file from the project root if it exists, using Node's `loadEnvFile` API, and load the environment variables into `process.env`. The `.env` file will only exist on the development machine and is crucial to properly test the extension in vscode's extension testing environment. This fixes the ability to mistakenly commit the dev testing path to git. As seen in commit be9d972 and removed in commit 9ff0857 of PR #20. With the .env file, this will never happen again. - Added the `addDevEnvVariables` function call to the top of the `extension.ts` file so it is the first thing it does and the env variables will be available in all files in development. - Added the usage of the `DEV_USER_EXTENSIONS_PATH` env variable to `ExtensionData::setExtensionDiscoveryPaths` method. So that when its available to use, it will override the `userExtensionsPath` variable with the path set in the env variable.
There was a problem hiding this comment.
Pull request overview
Adds developer-focused configuration hooks by loading local .env variables and allowing an environment-variable override for the user extensions discovery path.
Changes:
- Introduces
addDevEnvVariables()to load a local.envfile at startup. - Allows overriding the computed
userExtensionsPathviaDEV_USER_EXTENSIONS_PATH. - Ignores
.envin git to avoid committing local secrets.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/utils.ts |
Adds .env loading helper using process.loadEnvFile. |
src/extension.ts |
Invokes .env loading during extension module initialization. |
src/extensionData.ts |
Uses DEV_USER_EXTENSIONS_PATH to override extension discovery path. |
.gitignore |
Adds .env to ignored files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8 tasks
|
@yCodeTech I've opened a new pull request, #23, to work on those changes. Once the pull request is ready, I'll request review from you. |
A duplicate output channel is sometimes created when logging. Possibly because it is setup after `ExtensionData`, and any logs from that class or earlier in the run, will create additional channels, without realising there's one already created. - Fixed by moving `logger.setupOutputChannel` call up the run order to before the `addDevEnvVariables` call in the extension file. This should help prevent duplicate channels, and log to only one channel.
- Added `validateDevEnvVariables` util function to validate and sanitize the `DEV_USER_EXTENSIONS_PATH` env variable value. Added it's function call to `addDevEnvVariables` util function. This function is based on the code Copilot created in PR #23, but with significant improvement.
- Added `validateDevEnvVariables` util function to validate and sanitize the `DEV_USER_EXTENSIONS_PATH` env variable value. Added it's function call to `addDevEnvVariables` util function. This function is based on the code Copilot created in PR #23, but with significant improvement.
- Fixed `errorMsg` variable in `validateDevEnvVariables` util function to be initialised as an empty string. This avoids errors when trying to call `.length` on it later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces support for loading and validating development environment variables from a
.envfile, allowing for easier local development and testing. The most important changes are grouped below by theme:Development environment support:
addDevEnvVariablesfunction insrc/utils.tsthat loads environment variables from a local.envfile and validates them, specifically focusing onDEV_USER_EXTENSIONS_PATH.src/extension.tsto calladdDevEnvVariablesduring extension startup, ensuring development environment variables are loaded before initializing extension data.Environment variable validation:
src/utils.tsto sanitizeDEV_USER_EXTENSIONS_PATH, removing it from the environment and logging errors if the path is invalid or inaccessible.Extension discovery paths:
ExtensionData.setExtensionDiscoveryPathsinsrc/extensionData.tsto use theDEV_USER_EXTENSIONS_PATHenvironment variable if present, allowing custom user extension paths during development.Dependency updates:
pathmodule import insrc/utils.tsto support path resolution and validation for environment variables.~ Summary generated by Copilot